package cn.kgc.watch.web;

import cn.kgc.watch.entity.Collect;
import cn.kgc.watch.entity.ResultInfo;
import cn.kgc.watch.service.CollectService;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Date;

@CrossOrigin
@RestController
@RequestMapping("controller")
public class CollectListController {
    @Resource
    CollectService collectService;
    @GetMapping("/collectList")
    public ResultInfo collectList(Integer userId,Integer pageNum){
        if (pageNum==null){
            pageNum=1;
        }
        Integer pageSize=1;
        PageInfo<Collect> pageInfo=this.collectService.findAll(userId,pageNum,pageSize);
        return new ResultInfo(200,"查询成功",pageInfo);
    }
    @PostMapping
    public ResultInfo doAdd( Collect collect){
        collect.setCreateTime(new Date());
        this.collectService.add(collect);
        System.out.println("collect = " + collect);
        return new ResultInfo(200,"添加成功！",collect);
    }
    @DeleteMapping("/{collectId}")
    public ResultInfo romve(@PathVariable Integer collectId){
        this.collectService.remove(collectId);
        System.out.println("collectId = " + collectId);
        return new ResultInfo(200,"删除成功!",collectId);
    }
}
